﻿$(function() {
	$(".slide").css({ display: "none", position: "absolute" }).each(function(idx) {
		if (idx == 0)
			$(this).addClass("title_slide");
		else
			$(this).addClass("content_slide");
	});
	$(".title_slide").fadeIn(1000);
	var slideCount = $(".slide").length;
	$(document).keydown(function(e) {
		if (e.keyCode < 37 || 40 < e.keyCode)
			return;
		var current = $(".slide:visible")[0];
		var next = (e.keyCode == 37 || e.keyCode == 38)
							? $(current).prev()
							: $(current).next();
		var index = $(next).index();

		if (slideCount <= index)
			return;
			
		if (index < 0) {
			index = slideCount - 1;
			next = $(".slide:last");
		}

		if (e.keyCode % 2 == 0) {
			$(current).fadeOut(1000).delay(300);
			$(next).delay(300).fadeIn(1000);
		} else {
			$(current).hide();
			$(next).show();
		}
	});
});
